# 演示 python & pymysql 库的基本操作
from pymysql import Connection, connect

# 构建到MySql数据库的链接
conn = Connection(
    host="localhost",        # 主机名(IP)
    port=3306,             # mysql 默认端口是3306
    user="root",             # mysql 账户
    password="wl@1234"       # 账户密码
)
# print(conn.get_server_info())     # 测试链接是否成功

# 执行非出查询性质的SQL语句
cursor = conn.cursor()          # 获取到游标对象
# 选择数据库
conn.select_db("world")
# 执行sql
# cursor.execute("create table test_pymysql(id int);")

# 执行带有查询结果的sql语句
cursor.execute("select * from student where age > 18;")
results:tuple = cursor.fetchall()
for i in results:
    print(i)

# 关闭链接
conn.close()